package com.baosight.risk.service.xtaa.code.impl;

import com.baosight.risk.api.xtaa.code.IXtaaCodeTypeService;
import com.baosight.risk.base.mapper.BaseMapper;
import com.baosight.risk.base.redis.BaseRedis;
import com.baosight.risk.base.service.BaseServiceImpl;
import com.baosight.risk.mapper.xtaa.code.XtaaCodeTypeMapper;
import com.baosight.risk.service.xtaa.code.entity.XtaaCodeType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @desc:
 * @author: CuiShiHao
 **/
@Service
public class XtaaCodeTypeServiceImpl extends BaseServiceImpl<XtaaCodeType> implements IXtaaCodeTypeService {

    @Autowired
    private XtaaCodeTypeMapper xtaaCodeTypeMapper;

    @Autowired
    private BaseRedis redis;

    private String XTAA_CODE_KEY = "xtaa:code:key:";

    @Override
    public BaseMapper getMapper() {
        return xtaaCodeTypeMapper;
    }


    @Override
    public Integer updateType(XtaaCodeType type) {
        redis.deleteList(XTAA_CODE_KEY);
        return xtaaCodeTypeMapper.updateByPrimaryKeySelective(type);
    }

    @Override
    public Integer deleteType(String id) {
        XtaaCodeType type = xtaaCodeTypeMapper.selectByPrimaryKey(id);
        if (null == type) {
            return null;
        }
        redis.deleteList(XTAA_CODE_KEY);
        return xtaaCodeTypeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<XtaaCodeType> fuzyListByDDTypeName(String ddTypeName) {
        List<XtaaCodeType> resultList = xtaaCodeTypeMapper.fuzyListByDDTypeName(ddTypeName);
        return resultList;
    }
}
